#!/bin/bash

# Array sizes to test
sizes=(64 256 1024 4096 65536 262144 1048576)
size_labels=("64" "256" "256x4" "256x16" "256x256" "256x1024" "1024x1024")

echo "Starting CUDA Stream Performance Tests with different array sizes..."
echo "=================================================================="

# Build the CUDA program
echo "Building CUDA program..."
nvcc -o cuda_stream_test cuda_stream_test.cu
if [ $? -ne 0 ]; then
    echo "Error: Failed to build CUDA program"
    exit 1
fi

# Create output directory if it doesn't exist
mkdir -p output

# Test each array size
for i in "${!sizes[@]}"; do
    size=${sizes[$i]}
    label=${size_labels[$i]}
    
    echo ""
    echo "Testing array size: $size (${label})"
    echo "-----------------------------------"
    
    # Run the test and save output
    output_file="output/cuda_test_${label}.log"
    ./cuda_stream_test $size | tee "$output_file"
    
    if [ $? -eq 0 ]; then
        echo "Test completed successfully. Results saved to: $output_file"
    else
        echo "Test failed for array size: $size"
    fi
done

echo ""
echo "All tests completed!"
echo "Results are saved in the ./output directory:"
ls -la output/cuda_test_*.log